/// ----------------------------------------------
/// !!! 此文件由工具自动生成，请勿直接修改。 !!!
/// !!! Tabs to Spaces !!!
/// !!! 生成时间：2021-05-10 14:57:25.518
/// ----------------------------------------------

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
using DLC.Module.DataTable;

namespace DLC.Game.DataTable.ArchiveString.Editor
{
    public class ExcelExampleExampleStringAssetPostprocessor : AssetPostprocessor 
    {
        private const string filePath = "Assets/Example/Excel/Example.xlsx";
        private const string assetFilePath = "Assets/Example/Excel/ExcelExample_Example.txt";
        private const string sheetName = "ExcelExample";
    
        static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            foreach (string asset in importedAssets) 
            {
                if (!filePath.Equals (asset))
                    continue;
                
                ExcelExample dataTable = new ExcelExample();
                var data = AssetDatabase.LoadAssetAtPath<TextAsset>(assetFilePath);
                if (data != null)
                {
                    dataTable.ParseFromString(data.text);
                }

                ExcelQuery query = new ExcelQuery(filePath, sheetName);
                if (query != null && query.IsValid())
                {
                    dataTable.RemoveAllDataRows();
                    foreach (var da in query.Deserialize<ExcelExampleData>().ToArray())
                    {
                        dataTable.AddDataRow(da);
                    }
                    using (var writer = new StreamWriter(assetFilePath))
                    {
                        writer.Write(dataTable.ToString());
                        writer.Close();
                    }
                }
            }
        }
    }
}
